package demo1;

import java.util.Objects;
class Money implements Cloneable{
    public int money=12;

    @Override
    protected Object clone() throws CloneNotSupportedException {
        return super.clone();
    }

    @Override
    public String toString() {
        return "Money{" +
                "money=" + money +
                '}';
    }
}

public class Person implements Cloneable {
    public String name;
    Money money;
    public Person(String name) {
        this.name = name;
        money=new Money();
    }

    @Override
    protected Object clone()
            throws CloneNotSupportedException {
        //return super.clone();
        Person tmp = (Person) super.clone();
        tmp.money = (Money) this.money.clone();
        return tmp;
    }

    @Override
    public String toString() {
        return "Person{" +
                "name='" + name + '\'' +
                ", money=" + money +
                '}';
    }
}
